package actionForm;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class FindContactValidationForm extends ActionForm {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String findBy = null;
	private String email;
	private String lastName;
	private String firstName;
	
	public String getFindBy() {
		return findBy;
	}
	public void setFindBy(String findBy) {
		this.findBy = findBy;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if(( getFirstName()== null || getFirstName().length() < 1 ) && getFindBy().equals("firstName")) {
			errors.add("first name",new
					ActionMessage("creation.fn.error.required"));
		}
		if(( getLastName()== null || getLastName().length() < 1 ) && getFindBy().equals("lastName")) {
			errors.add("last name",new
					ActionMessage("creation.ln.error.required"));
		}
		if( (getEmail() == null || getEmail().length() < 1 ) && getFindBy().equals("email")){
			errors.add("email", new
					ActionMessage("creation.email.error.required"));
		}
		return errors;
	}
}
